package com.pz.art.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.pz.art.domain.AssoEvents;
import com.pz.art.service.EventsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动Controller
 *
 * @author ruoyi
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/system/events")
public class EventsController extends BaseController
{
    @Autowired
    private EventsService assoEventsService;

    /**
     * 查询活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:events:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssoEvents assoEvents)
    {
        startPage();
        List<AssoEvents> list = assoEventsService.selectAssoEventsList(assoEvents);
        return getDataTable(list);
    }

    /**
     * 导出活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:events:export')")
    @Log(title = "活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssoEvents assoEvents)
    {
        List<AssoEvents> list = assoEventsService.selectAssoEventsList(assoEvents);
        ExcelUtil<AssoEvents> util = new ExcelUtil<AssoEvents>(AssoEvents.class);
        util.exportExcel(response, list, "活动数据");
    }

    /**
     * 获取活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:events:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assoEventsService.selectAssoEventsById(id));
    }

    /**
     * 新增活动
     */
    @PreAuthorize("@ss.hasPermi('system:events:add')")
    @Log(title = "活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssoEvents assoEvents)
    {
        return toAjax(assoEventsService.insertAssoEvents(assoEvents));
    }

    /**
     * 修改活动
     */
    @PreAuthorize("@ss.hasPermi('system:events:edit')")
    @Log(title = "活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssoEvents assoEvents)
    {
        System.out.println(assoEvents.getId());
        AjaxResult  result = assoEventsService.updateAssoEvents(assoEvents.getId());
        System.out.println(result);
        return result;
    }

    /**
     * 删除活动
     */
    @PreAuthorize("@ss.hasPermi('system:events:remove')")
    @Log(title = "活动", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assoEventsService.deleteAssoEventsByIds(ids));
    }

    //获取待审核的活动列表
    @PreAuthorize("@ss.hasPermi('system:events:getexamineevents')")
    @GetMapping("/getexamineevents")
    public TableDataInfo getexamineevents(AssoEvents assoEvents)
    {
        startPage();
        List<AssoEvents> list = assoEventsService.selectApplyStatusAssoEventsList(assoEvents);
        return getDataTable(list);
    }

    //审核待审核的活动列表
    @PreAuthorize("@ss.hasPermi('system:events:examineevents')")
    @PutMapping("/examineevents")
    public AjaxResult examineevents(@RequestBody AssoEvents assoEvents)
    {
        return toAjax(assoEventsService.examineevents(assoEvents));
    }
}

